/**
* Created by ren on 2017/1/16.
*/
<template>
  <div class='morezcJsj moreGoods'>
    <div class="content" v-if="goodsData.length!==0">
      <div class="jsj">
        <div class="item" v-for="(item,index) in goodsData.content" @click="tojsjDetail(item.id)"
             style="background: #eeeeee">
          <div style="float: left;">
            <div style="margin-bottom:10px"><span>{{item.kinsonName}}</span></div>
            <div style="color:#ff9900">理财期限{{item.validity}}天</div>
          </div>
          <img src="../../assets/toright.png" style="float:right;margin-top: 15px;">
          <div style="float: right;margin-right: 100px;color:#ff9900;">
            <div style="margin-bottom:10px">{{(item.yield*100).toFixed(2)}}%</div>
            <div>年化黄金收益率</div>
          </div>
        </div>
      </div>
    </div>
    <div class="paging" v-if="goodsData!==''&&goodsData.totalPages>1">
      <img src="../../assets/prev.png" style="float: left;margin-top: 23px;cursor: pointer" @click="prev">
      <div class="page" style="float: left">
        <div v-for="(item,index) in goodsData.totalPages" v-if="goodsData.totalPages<9"
             :class="{active:index===nextPage}" @click="paging(index)">{{index+1}}
        </div>
        <template v-if="goodsData.totalPages>8">
          <template v-if="goodsData.totalPages-9<nextPage">
            <div v-for="(item,index) in goodsData.totalPages" v-if="index>goodsData.totalPages-9"
                 :class="{active:index===nextPage}" @click="paging(index)">{{index+1}}
            </div>
          </template>
          <template v-else>
            <div v-for="(item,index) in goodsData.totalPages" v-if="index<5+nextPage&&index>nextPage-1"
                 :class="{active:index===nextPage}"
                 @click="paging(index)">{{index+1}}
            </div>
            <div>……</div>
            <div v-for="(item,index) in goodsData.totalPages" v-if="index>goodsData.totalPages-3"
                 :class="{active:index===nextPage}" @click="paging(index)">{{index+1}}
            </div>
          </template>
        </template>
      </div>
      <img src="../../assets/next.png" style="float: left;margin-top: 23px;cursor: pointer" @click="next">
      <div class="total">共{{goodsData.totalPages}}页</div>
    </div>
    <Notify :parentThis='this'></Notify>
  </div>
</template>

<script>
  import API from '../../api'
  import Notify from '../Notify'
  import DTDetail from './DTDetail'
  import DtTqRecord from './DtTqRecord'
  export default {
    name: 'morezcJsj',
    components: {
      Notify,
      DTDetail,
      DtTqRecord
    },
    data: function () {
      return {
        notifyStatus: 2,
        goodsData: [],
        nextPage: 0,
        cutName: 'jsj'
      }
    },
    props: ['_parentThis'],
    methods: {
      paging: function (page) {
        this.nextPage = page
        switch (this.cutName) {
          case 'jsj':
            this.KinsonBuyRecord()
            break
          case 'dt':
            this.regularPutInRecord()
            break
          case 'sp':
            this.shoppingRecord()
            break
        }
      },
      prev: function () {
        if (this.nextPage > 0) {
          this.nextPage = this.nextPage - 1
          switch (this.cutName) {
            case 'jsj':
              this.KinsonBuyRecord()
              break
            case 'dt':
              this.regularPutInRecord()
              break
            case 'sp':
              this.shoppingRecord()
              break
          }
        }
      },
      next: function () {
        if (this.nextPage < this.goodsData.totalPages - 1) {
          this.nextPage = this.nextPage + 1
          switch (this.cutName) {
            case 'jsj':
              this.KinsonBuyRecord()
              break
            case 'dt':
              this.regularPutInRecord()
              break
            case 'sp':
              this.shoppingRecord()
              break
          }
        }
      },
      KinsonBuyRecord: function () {
        this.$http.post(API.findKinsonGoldList, {
          nextPage: this.nextPage,
          pageSize: 5
        }).then((ret) => {
          const result = ret.body
          if (result.code === 1) {
            this.goodsData = result.object
          } else {
            this.notifyStatus = '0|' + result.message
          }
        }, (err) => {
          console.log(err)
        })
      },
      tojsjDetail: function (id) {
        this._parentThis._parentThis.titHtml = '<span>购买记录 > <span>转存</span> > <span>金生金列表</span> > <span style="color: #f48315;">金生金详情</span></span>'
        this._parentThis.zcjsjDetailId = id
        this._parentThis.dtCutName = 'dingtouXcList'
      }
    },
    mounted: function () {
      this.KinsonBuyRecord()
    }
  }
</script>
